var namePrefix = "ghdskl";
function displaySignUp() {
    $("#username_cell").show();
    $("#username_cell").get(0).style.display="";
    $("#usermail_cell").show();
    $("#userpassword_cell").show();
    $("#passwordagain_cell").show();
    $("#signupsubmit").show();
    var label = $("#label");
    if (label.value) label.show();
    $("#loginsubmit").hide();
    $("#loginname_cell").hide();
    $("#loginpassword_cell").hide();
    $(document).keyup(function (event) {
        if (event.keyCode == '13') {
            $("#signupsubmit").click();
        }
    });
}
function displayLogin() {
    $("#username_cell").hide();
	$("#usermail_cell").hide();
    $("#userpassword_cell").hide();
    $("#passwordagain_cell").hide();
    $("#signupsubmit").hide()
    $("#label").hide();
	$("#loginsubmit").show();
    $("#loginname_cell").show();
    $("#loginpassword_cell").show();
    $(document).keyup(function (event) {
        if (event.keyCode == '13') {
            $("#loginsubmit").click();
        }
    });
}
function signUpSubmit() {
    // alert(1);
    // if(localStorage.db==null)localStorage.db=[];
    var userName = $("#username").get(0).value;
    if (userName == '') {
        $("#username").get(0).setCustomValidity("请输入用户名");
        return;
    }
    else if (localStorage.getItem(namePrefix + userName)) {
        $("#username").get(0).setCustomValidity("用户名已存在！");
        return;
    }
    else {
        $("#username").get(0).setCustomValidity("");
    }
    if (!$("#usermail").get(0).checkValidity()) {
        return
    }
    if ($("#userpassword").get(0).value.length < 6) {
        $("#userpassword").get(0).setCustomValidity("密码长度不少于六位！");
        return;
    }
    else {
        $("#userpassword").get(0).setCustomValidity("")
    }
    var passwd1 = $("#userpassword").get(0).value;
    var passwd2 = $("#passwordagain").get(0).value;
    if (passwd1 != passwd2) {
        $("#passwordagain").get(0).setCustomValidity("两次密码输入不一致!");
        return;
    }
    localStorage.setItem(namePrefix + userName, passwd1);
    localStorage.presentUser = userName;
    self.location = "./login_success.html";

    //            alert("heh");
}
function LoginSubmit() {
    var userName = $("#loginname").get(0).value;
    var passwd = $("#loginpassword").get(0).value;
    if (localStorage.getItem(namePrefix + userName) != passwd) {
        alert("用户名或密码错误！");
        return;
    }
    localStorage.presentUser = userName;
    self.location = "./login_success.html";
}
function setLabel() {
    // alert(1);
    var regxs = [];
    regxs.push(/[a-z]/g);
    regxs.push(/[0-9]/g);
    regxs.push(/(.[^a-z0-9])/g);
    var val = $("#userpassword").get(0).value;
    var len = val.length;
    var sec = 0;
    if (len >= 6) { // 至少六个字符
        for (var i = 0; i < regxs.length; i++) {
            if (val.match(regxs[i])) {
                sec++;
            }
        }
    }
    console.log(sec);
    var label = $("#label").get(0);
    if (val) {
        label.style.display = '';
    }
    else {
        label.style.display = 'none';
    }
    if (sec <= 1) label.innerHTML = "密码强度：弱";
    if (sec == 2) label.innerHTML = "密码强度：中";
    if (sec >= 3) label.innerHTML = "密码强度：强";
}
function checkUserName() { }
function checkPassword() { }
